package com.yfeng.security.servlet;

//import com.yfeng.security.SecurityManager;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * 一个Servlet监听器,用于在启动时候载入URL/ROLE进缓存
 * <p/>
 * User: raoqn
 * Date: 2009-2-6 17:18:55
 */
public class ServletContextLoaderListener implements ServletContextListener {
    public void contextInitialized(ServletContextEvent servletContextEvent) {

        ServletContext servletContext = servletContextEvent.getServletContext();
        SecurityManager sm = (SecurityManager) WebApplicationContextUtils.getWebApplicationContext(servletContext).getBean("securityManager");
        //Map urlAuthorities = sm.loadUrlAndRoleToCache();
        //servletContext.setAttribute("urlAuthorities", urlAuthorities);
    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext();
        servletContext.removeAttribute("urlAuthorities");
    }
}
